//
//  UINavigationItem+BKJCustomBackItem.m
//  BKJ
//
//  Created by 吴涛 on 16/2/19.
//  Copyright © 2016年 贝壳家iOS. All rights reserved.
//

#import "UINavigationItem+BKJCustomBackItem.h"
#import <objc/runtime.h>




@implementation UINavigationItem (BKJCustomBackItem)

+(void)load{
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    Method originalMethodImp = class_getInstanceMethod(self, @selector(backBarButtonItem));
    Method destMethodImp = class_getInstanceMethod(self, @selector(myCustomBackButton_backBarButtonItem));
    method_exchangeImplementations(originalMethodImp, destMethodImp);
  });
}

static char kCustomBackButtonKey;

-(UIBarButtonItem *)myCustomBackButton_backBarButtonItem{
//  UIBarButtonItem *item = [self myCustomBackButton_backBarbuttonItem];
//  if (item) {
//    return item;
//  }
   UIBarButtonItem *item = objc_getAssociatedObject(self, &kCustomBackButtonKey);
  if (!item) {
    item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
    objc_setAssociatedObject(self, &kCustomBackButtonKey, item, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  }
  return item;
}

- (void)setMyCustomBackButton_backBarButtonItem:(UIBarButtonItem *)myCustomBackButton_backBarButtonItem{
      objc_setAssociatedObject(self, &kCustomBackButtonKey, myCustomBackButton_backBarButtonItem, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
